home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / os.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  23.1 KB  |  823 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. """OS routines for Mac, NT, or Posix depending on what system we're on.
  5.  
  6. This exports:
  7.   - all functions from posix, nt, os2, mac, or ce, e.g. unlink, stat, etc.
  8.   - os.path is one of the modules posixpath, ntpath, or macpath
  9.   - os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
  10.   - os.curdir is a string representing the current directory ('.' or ':')
  11.   - os.pardir is a string representing the parent directory ('..' or '::')
  12.   - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\\\')
  13.   - os.extsep is the extension separator ('.' or '/')
  14.   - os.altsep is the alternate pathname separator (None or '/')
  15.   - os.pathsep is the component separator used in $PATH etc
  16.   - os.linesep is the line separator in text files ('\\r' or '\\n' or '\\r\\n')
  17.   - os.defpath is the default search path for executables
  18.   - os.devnull is the file path of the null device ('/dev/null', etc.)
  19.  
  20. Programs that import and use 'os' stand a better chance of being
  21. portable between different platforms.  Of course, they must then
  22. only use functions that are defined by all platforms (e.g., unlink
  23. and opendir), and leave all pathname manipulation to os.path
  24. (e.g., split and join).
  25. """
  26. import sys
  27. _names = sys.builtin_module_names
  28. __all__ = [
  29.     'altsep',
  30.     'curdir',
  31.     'pardir',
  32.     'sep',
  33.     'pathsep',
  34.     'linesep',
  35.     'defpath',
  36.     'name',
  37.     'path',
  38.     'devnull',
  39.     'SEEK_SET',
  40.     'SEEK_CUR',
  41.     'SEEK_END']
  42.  
  43. def _get_exports_list(module):
  44.     
  45.     try:
  46.         return list(module.__all__)
  47.     except AttributeError:
  48.         return _[1]
  49.     except:
  50.         []
  51.  
  52.  
  53. if 'posix' in _names:
  54.     name = 'posix'
  55.     linesep = '\n'
  56.     from posix import *
  57.     
  58.     try:
  59.         from posix import _exit
  60.     except ImportError:
  61.         pass
  62.  
  63.     import posixpath as path
  64.     import posix
  65.     __all__.extend(_get_exports_list(posix))
  66.     del posix
  67. elif 'nt' in _names:
  68.     name = 'nt'
  69.     linesep = '\r\n'
  70.     from nt import *
  71.     
  72.     try:
  73.         from nt import _exit
  74.     except ImportError:
  75.         pass
  76.  
  77.     import ntpath as path
  78.     import nt
  79.     __all__.extend(_get_exports_list(nt))
  80.     del nt
  81. elif 'os2' in _names:
  82.     name = 'os2'
  83.     linesep = '\r\n'
  84.     from os2 import *
  85.     
  86.     try:
  87.         from os2 import _exit
  88.     except ImportError:
  89.         pass
  90.  
  91.     if sys.version.find('EMX GCC') == -1:
  92.         import ntpath as path
  93.     else:
  94.         import os2emxpath as path
  95.         from _emx_link import link
  96.     import os2
  97.     __all__.extend(_get_exports_list(os2))
  98.     del os2
  99. elif 'mac' in _names:
  100.     name = 'mac'
  101.     linesep = '\r'
  102.     from mac import *
  103.     
  104.     try:
  105.         from mac import _exit
  106.     except ImportError:
  107.         pass
  108.  
  109.     import macpath as path
  110.     import mac
  111.     __all__.extend(_get_exports_list(mac))
  112.     del mac
  113. elif 'ce' in _names:
  114.     name = 'ce'
  115.     linesep = '\r\n'
  116.     from ce import *
  117.     
  118.     try:
  119.         from ce import _exit
  120.     except ImportError:
  121.         pass
  122.  
  123.     import ntpath as path
  124.     import ce
  125.     __all__.extend(_get_exports_list(ce))
  126.     del ce
  127. elif 'riscos' in _names:
  128.     name = 'riscos'
  129.     linesep = '\n'
  130.     from riscos import *
  131.     
  132.     try:
  133.         from riscos import _exit
  134.     except ImportError:
  135.         pass
  136.  
  137.     import riscospath as path
  138.     import riscos
  139.     __all__.extend(_get_exports_list(riscos))
  140.     del riscos
  141. else:
  142.     raise ImportError, 'no os specific module found'
  143. sys.modules['os.path'] = path
  144. from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull
  145. del _names
  146. SEEK_SET = 0
  147. SEEK_CUR = 1
  148. SEEK_END = 2
  149.  
  150. def makedirs(name, mode = 511):
  151.     '''makedirs(path [, mode=0777])
  152.  
  153.     Super-mkdir; create a leaf directory and all intermediate ones.
  154.     Works like mkdir, except that any intermediate path segment (not
  155.     just the rightmost) will be created if it does not exist.  This is
  156.     recursive.
  157.  
  158.     '''
  159.     (head, tail) = path.split(name)
  160.     if not tail:
  161.         (head, tail) = path.split(head)
  162.     
  163.     if head and tail and not path.exists(head):
  164.         makedirs(head, mode)
  165.         if tail == curdir:
  166.             return None
  167.         
  168.     
  169.     mkdir(name, mode)
  170.  
  171.  
  172. def removedirs(name):
  173.     '''removedirs(path)
  174.  
  175.     Super-rmdir; remove a leaf directory and all empty intermediate
  176.     ones.  Works like rmdir except that, if the leaf directory is
  177.     successfully removed, directories corresponding to rightmost path
  178.     segments will be pruned away until either the whole path is
  179.     consumed or an error occurs.  Errors during this latter phase are
  180.     ignored -- they generally mean that a directory was not empty.
  181.  
  182.     '''
  183.     rmdir(name)
  184.     (head, tail) = path.split(name)
  185.     if not tail:
  186.         (head, tail) = path.split(head)
  187.     
  188.     while head and tail:
  189.         
  190.         try:
  191.             rmdir(head)
  192.         except error:
  193.             break
  194.  
  195.         (head, tail) = path.split(head)
  196.  
  197.  
  198. def renames(old, new):
  199.     '''renames(old, new)
  200.  
  201.     Super-rename; create directories as necessary and delete any left
  202.     empty.  Works like rename, except creation of any intermediate
  203.     directories needed to make the new pathname good is attempted
  204.     first.  After the rename, directories corresponding to rightmost
  205.     path segments of the old name will be pruned way until either the
  206.     whole path is consumed or a nonempty directory is found.
  207.  
  208.     Note: this function can fail with the new directory structure made
  209.     if you lack permissions needed to unlink the leaf directory or
  210.     file.
  211.  
  212.     '''
  213.     (head, tail) = path.split(new)
  214.     if head and tail and not path.exists(head):
  215.         makedirs(head)
  216.     
  217.     rename(old, new)
  218.     (head, tail) = path.split(old)
  219.     if head and tail:
  220.         
  221.         try:
  222.             removedirs(head)
  223.         except error:
  224.             pass
  225.         except:
  226.             None<EXCEPTION MATCH>error
  227.         
  228.  
  229.     None<EXCEPTION MATCH>error
  230.  
  231. __all__.extend([
  232.     'makedirs',
  233.     'removedirs',
  234.     'renames'])
  235.  
  236. def walk(top, topdown = True, onerror = None):
  237.     '''Directory tree generator.
  238.  
  239.     For each directory in the directory tree rooted at top (including top
  240.     itself, but excluding \'.\' and \'..\'), yields a 3-tuple
  241.  
  242.         dirpath, dirnames, filenames
  243.  
  244.     dirpath is a string, the path to the directory.  dirnames is a list of
  245.     the names of the subdirectories in dirpath (excluding \'.\' and \'..\').
  246.     filenames is a list of the names of the non-directory files in dirpath.
  247.     Note that the names in the lists are just names, with no path components.
  248.     To get a full path (which begins with top) to a file or directory in
  249.     dirpath, do os.path.join(dirpath, name).
  250.  
  251.     If optional arg \'topdown\' is true or not specified, the triple for a
  252.     directory is generated before the triples for any of its subdirectories
  253.     (directories are generated top down).  If topdown is false, the triple
  254.     for a directory is generated after the triples for all of its
  255.     subdirectories (directories are generated bottom up).
  256.  
  257.     When topdown is true, the caller can modify the dirnames list in-place
  258.     (e.g., via del or slice assignment), and walk will only recurse into the
  259.     subdirectories whose names remain in dirnames; this can be used to prune
  260.     the search, or to impose a specific order of visiting.  Modifying
  261.     dirnames when topdown is false is ineffective, since the directories in
  262.     dirnames have already been generated by the time dirnames itself is
  263.     generated.
  264.  
  265.     By default errors from the os.listdir() call are ignored.  If
  266.     optional arg \'onerror\' is specified, it should be a function; it
  267.     will be called with one argument, an os.error instance.  It can
  268.     report the error to continue with the walk, or raise the exception
  269.     to abort the walk.  Note that the filename is available as the
  270.     filename attribute of the exception object.
  271.  
  272.     Caution:  if you pass a relative pathname for top, don\'t change the
  273.     current working directory between resumptions of walk.  walk never
  274.     changes the current directory, and assumes that the client doesn\'t
  275.     either.
  276.  
  277.     Example:
  278.  
  279.     from os.path import join, getsize
  280.     for root, dirs, files in walk(\'python/Lib/email\'):
  281.         print root, "consumes",
  282.         print sum([getsize(join(root, name)) for name in files]),
  283.         print "bytes in", len(files), "non-directory files"
  284.         if \'CVS\' in dirs:
  285.             dirs.remove(\'CVS\')  # don\'t visit CVS directories
  286.     '''
  287.     join = join
  288.     isdir = isdir
  289.     islink = islink
  290.     import os.path
  291.     
  292.     try:
  293.         names = listdir(top)
  294.     except error:
  295.         err = None
  296.         if onerror is not None:
  297.             onerror(err)
  298.         
  299.         return None
  300.  
  301.     dirs = []
  302.     nondirs = []
  303.     for name in names:
  304.         if isdir(join(top, name)):
  305.             dirs.append(name)
  306.             continue
  307.         nondirs.append(name)
  308.     
  309.     if topdown:
  310.         yield (top, dirs, nondirs)
  311.     
  312.     for name in dirs:
  313.         path = join(top, name)
  314.         if not islink(path):
  315.             for x in walk(path, topdown, onerror):
  316.                 yield x
  317.             
  318.     
  319.     if not topdown:
  320.         yield (top, dirs, nondirs)
  321.     
  322.  
  323. __all__.append('walk')
  324.  
  325. try:
  326.     environ
  327. except NameError:
  328.     environ = { }
  329.  
  330.  
  331. def execl(file, *args):
  332.     '''execl(file, *args)
  333.  
  334.     Execute the executable file with argument list args, replacing the
  335.     current process. '''
  336.     execv(file, args)
  337.  
  338.  
  339. def execle(file, *args):
  340.     '''execle(file, *args, env)
  341.  
  342.     Execute the executable file with argument list args and
  343.     environment env, replacing the current process. '''
  344.     env = args[-1]
  345.     execve(file, args[:-1], env)
  346.  
  347.  
  348. def execlp(file, *args):
  349.     '''execlp(file, *args)
  350.  
  351.     Execute the executable file (which is searched for along $PATH)
  352.     with argument list args, replacing the current process. '''
  353.     execvp(file, args)
  354.  
  355.  
  356. def execlpe(file, *args):
  357.     '''execlpe(file, *args, env)
  358.  
  359.     Execute the executable file (which is searched for along $PATH)
  360.     with argument list args and environment env, replacing the current
  361.     process. '''
  362.     env = args[-1]
  363.     execvpe(file, args[:-1], env)
  364.  
  365.  
  366. def execvp(file, args):
  367.     '''execp(file, args)
  368.  
  369.     Execute the executable file (which is searched for along $PATH)
  370.     with argument list args, replacing the current process.
  371.     args may be a list or tuple of strings. '''
  372.     _execvpe(file, args)
  373.  
  374.  
  375. def execvpe(file, args, env):
  376.     '''execvpe(file, args, env)
  377.  
  378.     Execute the executable file (which is searched for along $PATH)
  379.     with argument list args and environment env , replacing the
  380.     current process.
  381.     args may be a list or tuple of strings. '''
  382.     _execvpe(file, args, env)
  383.  
  384. __all__.extend([
  385.     'execl',
  386.     'execle',
  387.     'execlp',
  388.     'execlpe',
  389.     'execvp',
  390.     'execvpe'])
  391.  
  392. def _execvpe(file, args, env = None):
  393.     ENOENT = ENOENT
  394.     ENOTDIR = ENOTDIR
  395.     import errno
  396.     if env is not None:
  397.         func = execve
  398.         argrest = (args, env)
  399.     else:
  400.         func = execv
  401.         argrest = (args,)
  402.         env = environ
  403.     (head, tail) = path.split(file)
  404.     if head:
  405.         func(file, *argrest)
  406.         return None
  407.     
  408.     if 'PATH' in env:
  409.         envpath = env['PATH']
  410.     else:
  411.         envpath = defpath
  412.     PATH = envpath.split(pathsep)
  413.     saved_exc = None
  414.     saved_tb = None
  415.     for dir in PATH:
  416.         fullname = path.join(dir, file)
  417.         
  418.         try:
  419.             func(fullname, *argrest)
  420.         continue
  421.         except error:
  422.             e = None
  423.             tb = sys.exc_info()[2]
  424.             if e.errno != ENOENT and e.errno != ENOTDIR and saved_exc is None:
  425.                 saved_exc = e
  426.                 saved_tb = tb
  427.             
  428.             saved_exc is None
  429.         
  430.  
  431.     
  432.     if saved_exc:
  433.         raise error, saved_exc, saved_tb
  434.     
  435.     raise error, e, tb
  436.  
  437.  
  438. try:
  439.     putenv
  440. except NameError:
  441.     pass
  442.  
  443. import UserDict
  444. if name in ('os2', 'nt'):
  445.     
  446.     def unsetenv(key):
  447.         putenv(key, '')
  448.  
  449.  
  450. if name == 'riscos':
  451.     from riscosenviron import _Environ
  452. elif name in ('os2', 'nt'):
  453.     
  454.     class _Environ(UserDict.IterableUserDict):
  455.         
  456.         def __init__(self, environ):
  457.             UserDict.UserDict.__init__(self)
  458.             data = self.data
  459.             for k, v in environ.items():
  460.                 data[k.upper()] = v
  461.             
  462.  
  463.         
  464.         def __setitem__(self, key, item):
  465.             putenv(key, item)
  466.             self.data[key.upper()] = item
  467.  
  468.         
  469.         def __getitem__(self, key):
  470.             return self.data[key.upper()]
  471.  
  472.         
  473.         try:
  474.             unsetenv
  475.         except NameError:
  476.             
  477.             def __delitem__(self, key):
  478.                 del self.data[key.upper()]
  479.  
  480.  
  481.         
  482.         def __delitem__(self, key):
  483.             unsetenv(key)
  484.             del self.data[key.upper()]
  485.  
  486.         
  487.         def has_key(self, key):
  488.             return key.upper() in self.data
  489.  
  490.         
  491.         def __contains__(self, key):
  492.             return key.upper() in self.data
  493.  
  494.         
  495.         def get(self, key, failobj = None):
  496.             return self.data.get(key.upper(), failobj)
  497.  
  498.         
  499.         def update(self, dict = None, **kwargs):
  500.             if dict:
  501.                 
  502.                 try:
  503.                     keys = dict.keys()
  504.                 except AttributeError:
  505.                     for k, v in dict:
  506.                         self[k] = v
  507.                     
  508.  
  509.                 for k in keys:
  510.                     self[k] = dict[k]
  511.                 
  512.             
  513.             if kwargs:
  514.                 self.update(kwargs)
  515.             
  516.  
  517.         
  518.         def copy(self):
  519.             return dict(self)
  520.  
  521.  
  522. else:
  523.     
  524.     class _Environ(UserDict.IterableUserDict):
  525.         
  526.         def __init__(self, environ):
  527.             UserDict.UserDict.__init__(self)
  528.             self.data = environ
  529.  
  530.         
  531.         def __setitem__(self, key, item):
  532.             putenv(key, item)
  533.             self.data[key] = item
  534.  
  535.         
  536.         def update(self, dict = None, **kwargs):
  537.             if dict:
  538.                 
  539.                 try:
  540.                     keys = dict.keys()
  541.                 except AttributeError:
  542.                     for k, v in dict:
  543.                         self[k] = v
  544.                     
  545.  
  546.                 for k in keys:
  547.                     self[k] = dict[k]
  548.                 
  549.             
  550.             if kwargs:
  551.                 self.update(kwargs)
  552.             
  553.  
  554.         
  555.         try:
  556.             unsetenv
  557.         except NameError:
  558.             pass
  559.  
  560.         
  561.         def __delitem__(self, key):
  562.             unsetenv(key)
  563.             del self.data[key]
  564.  
  565.         
  566.         def copy(self):
  567.             return dict(self)
  568.  
  569.  
  570. environ = _Environ(environ)
  571.  
  572. def getenv(key, default = None):
  573.     """Get an environment variable, return None if it doesn't exist.
  574.     The optional second argument can specify an alternate default."""
  575.     return environ.get(key, default)
  576.  
  577. __all__.append('getenv')
  578.  
  579. def _exists(name):
  580.     
  581.     try:
  582.         eval(name)
  583.         return True
  584.     except NameError:
  585.         return False
  586.  
  587.  
  588. if _exists('fork') and not _exists('spawnv') and _exists('execv'):
  589.     P_WAIT = 0
  590.     P_NOWAIT = P_NOWAITO = 1
  591.     
  592.     def _spawnvef(mode, file, args, env, func):
  593.         pid = fork()
  594.         if not pid:
  595.             
  596.             try:
  597.                 if env is None:
  598.                     func(file, args)
  599.                 else:
  600.                     func(file, args, env)
  601.             _exit(127)
  602.  
  603.         elif mode == P_NOWAIT:
  604.             return pid
  605.         
  606.         while None:
  607.             (wpid, sts) = waitpid(pid, 0)
  608.             if WIFSTOPPED(sts):
  609.                 continue
  610.                 continue
  611.             if WIFSIGNALED(sts):
  612.                 return -WTERMSIG(sts)
  613.                 continue
  614.             if WIFEXITED(sts):
  615.                 return WEXITSTATUS(sts)
  616.                 continue
  617.             raise error, 'Not stopped, signaled or exited???'
  618.             continue
  619.             return None
  620.  
  621.     
  622.     def spawnv(mode, file, args):
  623.         """spawnv(mode, file, args) -> integer
  624.  
  625. Execute file with arguments from args in a subprocess.
  626. If mode == P_NOWAIT return the pid of the process.
  627. If mode == P_WAIT return the process's exit code if it exits normally;
  628. otherwise return -SIG, where SIG is the signal that killed it. """
  629.         return _spawnvef(mode, file, args, None, execv)
  630.  
  631.     
  632.     def spawnve(mode, file, args, env):
  633.         """spawnve(mode, file, args, env) -> integer
  634.  
  635. Execute file with arguments from args in a subprocess with the
  636. specified environment.
  637. If mode == P_NOWAIT return the pid of the process.
  638. If mode == P_WAIT return the process's exit code if it exits normally;
  639. otherwise return -SIG, where SIG is the signal that killed it. """
  640.         return _spawnvef(mode, file, args, env, execve)
  641.  
  642.     
  643.     def spawnvp(mode, file, args):
  644.         """spawnvp(mode, file, args) -> integer
  645.  
  646. Execute file (which is looked for along $PATH) with arguments from
  647. args in a subprocess.
  648. If mode == P_NOWAIT return the pid of the process.
  649. If mode == P_WAIT return the process's exit code if it exits normally;
  650. otherwise return -SIG, where SIG is the signal that killed it. """
  651.         return _spawnvef(mode, file, args, None, execvp)
  652.  
  653.     
  654.     def spawnvpe(mode, file, args, env):
  655.         """spawnvpe(mode, file, args, env) -> integer
  656.  
  657. Execute file (which is looked for along $PATH) with arguments from
  658. args in a subprocess with the supplied environment.
  659. If mode == P_NOWAIT return the pid of the process.
  660. If mode == P_WAIT return the process's exit code if it exits normally;
  661. otherwise return -SIG, where SIG is the signal that killed it. """
  662.         return _spawnvef(mode, file, args, env, execvpe)
  663.  
  664.  
  665. if _exists('spawnv'):
  666.     
  667.     def spawnl(mode, file, *args):
  668.         """spawnl(mode, file, *args) -> integer
  669.  
  670. Execute file with arguments from args in a subprocess.
  671. If mode == P_NOWAIT return the pid of the process.
  672. If mode == P_WAIT return the process's exit code if it exits normally;
  673. otherwise return -SIG, where SIG is the signal that killed it. """
  674.         return spawnv(mode, file, args)
  675.  
  676.     
  677.     def spawnle(mode, file, *args):
  678.         """spawnle(mode, file, *args, env) -> integer
  679.  
  680. Execute file with arguments from args in a subprocess with the
  681. supplied environment.
  682. If mode == P_NOWAIT return the pid of the process.
  683. If mode == P_WAIT return the process's exit code if it exits normally;
  684. otherwise return -SIG, where SIG is the signal that killed it. """
  685.         env = args[-1]
  686.         return spawnve(mode, file, args[:-1], env)
  687.  
  688.     __all__.extend([
  689.         'spawnv',
  690.         'spawnve',
  691.         'spawnl',
  692.         'spawnle'])
  693.  
  694. if _exists('spawnvp'):
  695.     
  696.     def spawnlp(mode, file, *args):
  697.         """spawnlp(mode, file, *args) -> integer
  698.  
  699. Execute file (which is looked for along $PATH) with arguments from
  700. args in a subprocess with the supplied environment.
  701. If mode == P_NOWAIT return the pid of the process.
  702. If mode == P_WAIT return the process's exit code if it exits normally;
  703. otherwise return -SIG, where SIG is the signal that killed it. """
  704.         return spawnvp(mode, file, args)
  705.  
  706.     
  707.     def spawnlpe(mode, file, *args):
  708.         """spawnlpe(mode, file, *args, env) -> integer
  709.  
  710. Execute file (which is looked for along $PATH) with arguments from
  711. args in a subprocess with the supplied environment.
  712. If mode == P_NOWAIT return the pid of the process.
  713. If mode == P_WAIT return the process's exit code if it exits normally;
  714. otherwise return -SIG, where SIG is the signal that killed it. """
  715.         env = args[-1]
  716.         return spawnvpe(mode, file, args[:-1], env)
  717.  
  718.     __all__.extend([
  719.         'spawnvp',
  720.         'spawnvpe',
  721.         'spawnlp',
  722.         'spawnlpe'])
  723.  
  724. if _exists('fork'):
  725.     if not _exists('popen2'):
  726.         
  727.         def popen2(cmd, mode = 't', bufsize = -1):
  728.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  729.             may be a sequence, in which case arguments will be passed directly to
  730.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  731.             is a string it will be passed to the shell (as with os.system()). If
  732.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  733.             file objects (child_stdin, child_stdout) are returned."""
  734.             import popen2
  735.             (stdout, stdin) = popen2.popen2(cmd, bufsize)
  736.             return (stdin, stdout)
  737.  
  738.         __all__.append('popen2')
  739.     
  740.     if not _exists('popen3'):
  741.         
  742.         def popen3(cmd, mode = 't', bufsize = -1):
  743.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  744.             may be a sequence, in which case arguments will be passed directly to
  745.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  746.             is a string it will be passed to the shell (as with os.system()). If
  747.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  748.             file objects (child_stdin, child_stdout, child_stderr) are returned."""
  749.             import popen2
  750.             (stdout, stdin, stderr) = popen2.popen3(cmd, bufsize)
  751.             return (stdin, stdout, stderr)
  752.  
  753.         __all__.append('popen3')
  754.     
  755.     if not _exists('popen4'):
  756.         
  757.         def popen4(cmd, mode = 't', bufsize = -1):
  758.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  759.             may be a sequence, in which case arguments will be passed directly to
  760.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  761.             is a string it will be passed to the shell (as with os.system()). If
  762.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  763.             file objects (child_stdin, child_stdout_stderr) are returned."""
  764.             import popen2
  765.             (stdout, stdin) = popen2.popen4(cmd, bufsize)
  766.             return (stdin, stdout)
  767.  
  768.         __all__.append('popen4')
  769.     
  770.  
  771. import copy_reg as _copy_reg
  772.  
  773. def _make_stat_result(tup, dict):
  774.     return stat_result(tup, dict)
  775.  
  776.  
  777. def _pickle_stat_result(sr):
  778.     (type, args) = sr.__reduce__()
  779.     return (_make_stat_result, args)
  780.  
  781.  
  782. try:
  783.     _copy_reg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
  784. except NameError:
  785.     pass
  786.  
  787.  
  788. def _make_statvfs_result(tup, dict):
  789.     return statvfs_result(tup, dict)
  790.  
  791.  
  792. def _pickle_statvfs_result(sr):
  793.     (type, args) = sr.__reduce__()
  794.     return (_make_statvfs_result, args)
  795.  
  796.  
  797. try:
  798.     _copy_reg.pickle(statvfs_result, _pickle_statvfs_result, _make_statvfs_result)
  799. except NameError:
  800.     pass
  801.  
  802. if not _exists('urandom'):
  803.     
  804.     def urandom(n):
  805.         '''urandom(n) -> str
  806.  
  807.         Return a string of n random bytes suitable for cryptographic use.
  808.  
  809.         '''
  810.         
  811.         try:
  812.             _urandomfd = open('/dev/urandom', O_RDONLY)
  813.         except (OSError, IOError):
  814.             raise NotImplementedError('/dev/urandom (or equivalent) not found')
  815.  
  816.         bytes = ''
  817.         while len(bytes) < n:
  818.             bytes += read(_urandomfd, n - len(bytes))
  819.         close(_urandomfd)
  820.         return bytes
  821.  
  822.  
  823.